﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using TheDrinksApp.Models;
using TheDrinksApp.Database;
namespace TheDrinksApp.Screen.Order
{
    public partial class OrderSizeItem : UserControl
    {
        private ObjectSize thisSize;
        private int count = 0;
        private int stt = -1;
        public int Count
        {
            get { return count; }
            set 
            {
                if (value >= 0)
                {
                    count = value;
                    tbCount.Text = count.ToString();
                }
            }
        }

        public ObjectSize ThisSize
        {
            get { return thisSize; }
            set 
            {
                thisSize = value;
                tbSizeName.Text = thisSize.SizeName.ToUpper();
            }
        }
        public OrderSizeItem(ObjectSize size)
        {
            InitializeComponent();
            ThisSize = size;
            
        }

        private void btnSubCount_Click(object sender, RoutedEventArgs e)
        {
            if ( Count > 0 )
                Count--;
            if (stt >= 0 && stt < Util.orderItems.Count)
                Util.orderItems[stt].quantity = count;
        }

        private void btnAddCount_Click(object sender, RoutedEventArgs e)
        {
            if (Count < 99 )
                Count++;
            if (stt >= 0 && stt < Util.orderItems.Count)
                Util.orderItems[stt].quantity = count;
        }

        private void UserControl_Loaded_1(object sender, RoutedEventArgs e)
        {
            CurrentOrderDAO current = new CurrentOrderDAO();
            current.category = Util.currentOrder.category;
            current.drink = Util.currentOrder.drink;
            current.size = thisSize;
            Util.orderItems.Add(current);
            stt = Util.orderItems.Count - 1;
            Count = 0;
        }
    }
}
